package com.lanswon.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.common.enums.ArticleStatus;
import com.lanswon.entity.ArticleVO;
import com.lanswon.entity.BottomNavigation;
import com.lanswon.service.ArticleService;

@Controller
@RequestMapping("admin/smkManage")
public class SMKManageController {
	
	@Autowired
	private ArticleService articleService;
	
	@RequestMapping("index/{manageType}")
	public String index(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap,
			@PathVariable(value="manageType")Integer manageType ) {
		
		ArticleVO article = null;
		Map<String, Object>  accessMap = new HashMap<>();
		if(manageType!=null) {
			accessMap.put("articleType", manageType);
			accessMap.put("articleStatus", ArticleStatus.ARTICLE_STATUS_NOMAL.getCode());
			List<ArticleVO> articleList = articleService.findArticleByCondition(accessMap);
			if(articleList!=null&&articleList.size()>0) {
				article = articleList.get(0);
			}
		}
		modelMap.addAttribute("manageType", manageType);
		modelMap.addAttribute("article", article);
		return "admin/smkManage/index";
	}
	
	@RequestMapping("addAndUpdateBottomNav")
	@ResponseBody
	public Map<String, Object> addAndUpdateBottomNav(HttpServletRequest request,HttpServletResponse response,BottomNavigation bottomNav){
		Map<String, Object> viewMap = new HashMap<>();
		
		try {
			
			viewMap.put("code", 1);
			viewMap.put("msg", "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 2);
			viewMap.put("msg", "操作有误");
		}
		return viewMap;
	}
}
